var baseUrl="/weixin/";
//相关业务逻辑
$(function(){
	page.bindTag();
	page.getAllCompany();
});

var page={//页面总变量 
		//绑定页面元素
		bindTag:function(){
			$("#querryReportBtn").bind("click",function(){
				page.getAllCompany();
			});
		},
		getAllCompany:function(){
			var companyName=$("#companyName").val();
			ajaxUtil.ajaxRuquestNoQuan(baseUrl+"company/getAllCompany",{"companyName":companyName},function(data){
				var html="";
				for(var i=0;i<data.length;i++){
					var btnHtml="<button class='btn agree' value='"+data[i].name+"'>免费</button> &nbsp;&nbsp;<button class='btn pay' value='"+data[i].name+"'>付费</button> &nbsp;&nbsp; <button class='btn refuse' value='"+data[i].name+"'>拒绝</button>";
					var status='未审核';
					if(data[i].status=='1'){
						btnHtml='';
						status='付费';
					}
					if(data[i].status=='2'){
						btnHtml='';
						status='已拒绝';
					}
					if(data[i].status=='3'){
						btnHtml='';
						status='收费';
					}
					html+="<tr>" +
					        "<td style='max-width:100px;'>"+data[i].name+"</td>" +
							"<td style='max-width:40px;'>"+data[i].userName+"</td>" +
							"<td style='max-width:20px;'>"+data[i].phone+"</td>" +
							"<td style='max-width:20px;'>"+status+"</td>" +
							"<td style='max-width:20px;'>"+btnHtml+"</td>"
						  "</tr>";
				}
				$("#reportTable").html(html);
				page.approvalBind();
			});
		},
		approvalBind:function(){
			$(".btn.agree").bind("click",function(){
				var companyName=$(this).val();
				page.approvalCompany(companyName,3);
			});
			$(".btn.refuse").bind("click",function(){
				var companyName=$(this).val();
				page.approvalCompany(companyName,2);
			});
			$(".btn.pay").bind("click",function(){
				var companyName=$(this).val();
				page.approvalCompany(companyName,1);
			});
		},
		//审核公司
		approvalCompany:function(companyName,status){
			ajaxUtil.ajaxRuquestNoQuan(baseUrl+"company/approvalCompany",{"status":status,"companyName":companyName},function(data){
				layAlert(data);
				page.getAllCompany();
			});
		}
}